const { port1, port2 } = new MessageChannel();

const showMsgEle = document.getElementById("show-msg");
const inputMsgEle = document.getElementById("input-msg-ele");
const sendMsgBtn = document.getElementById("send-msg-btn");

sendMsgBtn.addEventListener("click", (event) => {
  console.log(inputMsgEle.value);
  window.postMessage(
    {
      form: "testA",
      value: inputMsgEle.value,
    },
    "*",
    [port2]
  );
});

window.addEventListener("message", (e) => {
  console.log("xxx");
  e.port[0].postMessage("来自index2.html的信息");
});

// port1.onmessage = function (event) {
//   showMsgEle.value = event.data.value;
// };
